import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:my_desk_flutter/api/wan_api.dart';
import 'package:my_desk_flutter/controller/auth_controller.dart';
import 'package:my_desk_flutter/model/person_info.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'person_provider.g.dart';

@riverpod
Future<PersonInfo?> personInfo(PersonInfoRef ref) async {
  ref.state = const AsyncLoading();
  CancelToken cancelToken = CancelToken();
  ref.onDispose(() {
    log("取消请求");
    cancelToken.cancel();
  });
  final auth = await ref.watch(authControllerProvider.future);
  if (auth.isAuth) {
    log("已登录 获取信息");
    final result = await ref.read(wanApiProvider).personInfo(cancelToken);
    return result.data;
  }
  return null;
}
